<script>
import reportChild from "../student_report/components/reportChild.vue"
import RealTimeClock from "../student_report/components/RealTimeClock.vue";
import * as echarts from "echarts";

export default {
  mounted(){
    this.doFull();
    this.initChart();
    this.initOnlinePeople();
    this.totalPeopleFunction();
    this.suspendSchoolingTotalPeople();
    this.initDisciplinaryActionPeople();
    this.initPeopleDistribution();
    this.initDistributionOfProfessionalPersonnel();
  },
  components:{
    RealTimeClock,
    reportChild
  },
  data(){
    return{

    }
  },
  methods:{
    initDistributionOfProfessionalPersonnel() {
      // 获取图表容器
      const chartDom  = this.$refs.distributionOfProfessionalPersonnel
      console.log(chartDom)
      const myChart = echarts.init(chartDom);

      // 图表配置项
      const option = {
        grid: {
          bottom: "13%",    // 设置底部距离
          left:"10%"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
          axisLabel: {
            color: "#fff", // x轴文字颜色
          },
          axisLine: {
            show: false, // 隐藏 x 轴的轴线
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
              width: 1, // 网格线宽度
              type: "dashed", // 可选: 'solid' 或 'dashed'
            },
          }
        },
        yAxis: {
          type: "category",
          data: ["类别A", "类别B", "类别C", "类别D", "类别E","类别E","类别E","类别E","类别E"],
          axisLabel: {
            color: "#fff", // x轴文字颜色
            fontSize: 15,
          },
          axisLine: {
            show: false, // 隐藏 x 轴的轴线
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
              width: 1, // 网格线宽度
              type: "dashed", // 可选: 'solid' 或 'dashed'
            },
          }
        },
        series: [
          {
            name: "数据",
            type: "bar",
            data: [120, 200, 150, 80, 70, 70, 70, 70, 70],
            avoidLabelOverlap: false,
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                { offset: 0, color: "rgb(0,212,255)" },
                { offset: 1, color: "rgb(0,125,255)" },
              ]),
            },
            barWidth: "40%",
            label: {
              show: true,
              position: "right", // 显示在柱子顶部
              color: "#fff", // 数值颜色
              fontSize: 12, // 数值字体大小
            },
          },
        ],
      };

      // 设置图表选项
      myChart.setOption(option);

      // 监听窗口大小变化，自动调整图表大小
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
    suspendSchoolingTotalPeople() {
      // 获取图表容器
      const chartDom  = this.$refs.chartContainer
      console.log(chartDom)
      const myChart = echarts.init(chartDom);

      // 图表配置项
      const option = {
        grid: {
          bottom: "23%",    // 设置底部距离
          left:"13%"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
          axisLabel: {
            color: "#fff", // x轴文字颜色
          },
          axisLine: {
            show: false, // 隐藏 x 轴的轴线
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
              width: 1, // 网格线宽度
              type: "dashed", // 可选: 'solid' 或 'dashed'
            },
          }
        },
        yAxis: {
          type: "category",
          data: ["类别A", "类别B", "类别C", "类别D", "类别E"],
          axisLabel: {
            color: "#fff", // x轴文字颜色
            fontSize: 15,
          },
          axisLine: {
            show: false, // 隐藏 x 轴的轴线
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
              width: 1, // 网格线宽度
              type: "dashed", // 可选: 'solid' 或 'dashed'
            },
          }
        },
        series: [
          {
            name: "数据",
            type: "bar",
            data: [120, 200, 150, 80, 70],
            avoidLabelOverlap: false,
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                { offset: 0, color: "rgb(255,214,126)" },
                { offset: 1, color: "rgb(255,160,77)" },
              ]),
            },
            barWidth: "40%",
            label: {
              show: true,
              position: "right", // 显示在柱子顶部
              color: "#fff", // 数值颜色
              fontSize: 12, // 数值字体大小
            },
          },
        ],
      };

      // 设置图表选项
      myChart.setOption(option);

      // 监听窗口大小变化，自动调整图表大小
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
    totalPeopleFunction() {
      // 获取 DOM 元素
      const chartDom = this.$refs.totalPeople;

      // 初始化 ECharts 实例
      this.chart = echarts.init(chartDom);

      // 配置项
      const option = {
        tooltip: {
          trigger: "item",
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          right: '10%', // 图例靠右
          top: '77%', // 图例居中
          textStyle: {
            color: '#fff' // 图例文字颜色
          },
        },
        series: [
          {
            name: "数据来源",
            type: "pie",
            center: ['50%', '38%'],
            radius: ["40%", "70%"], // 定义内外半径，形成空心效果
            avoidLabelOverlap: false,
            label: {
              formatter: '{c}', // 显示数值
              color: '#fff',
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "20",
                fontWeight: "bold",
              },
            },

            labelLine: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            },
            data: [
              { value: 40, name: "类别A" },
              { value: 20, name: "类别B" },
              { value: 15, name: "类别C" },
              { value: 25, name: "类别D" },
            ],
          },
        ],
      };

      // 设置配置项
      this.chart.setOption(option);
    },
    doFull() {
      this.$store.dispatch('app/toggleSideBarHide', true);
      document.querySelector('.navbar').style.display = "none";
      document.querySelector('.tags-view-container').style.display = "none";
    },
    notFull() {
      this.$store.dispatch('app/toggleSideBarHide', false);
      document.querySelector('.navbar').style.display = "block";
      document.querySelector('.tags-view-container').style.display = "block";
    },
    initPeopleDistribution() {
      // 初始化图表
      const chart = echarts.init(this.$refs.peopleDistribution);

      // 配置项
      const option = {
        title: {
          text: '',
          left: 'center',
          top: '10%',
          textStyle: {
            color: '#333',
            fontSize: 18
          }
        },

        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical', // 图例垂直布局2
          right: '0%', // 图例靠右
          top: 'center', // 图例居中
          textStyle: {
            color: '#fff' // 图例文字颜色
          },
        },
        series: [
          {
            name: '学生分布',
            type: 'pie',
            radius: '50%',
            center: ['38%', '50%'],
            data: [
              {value: 2334, name: '机电工程学院'},
              {value: 2730, name: '交通工程学院'},
              {value: 2499, name: '土木建筑工程学院'},
              {value: 2640, name: '信息工程学院'}
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            label: {
              color: '#fff',
              formatter: '{c}', // 显示数值
            }
          }
        ],
      };

      // 设置配置项
      chart.setOption(option);
    },
    initDisciplinaryActionPeople() {
      // 初始化图表
      const chart = echarts.init(this.$refs.disciplinaryActionPeople);

      // 配置项
      const option = {
        title: {
          text: '',
          left: 'center',
          top: '10%',
          textStyle: {
            color: '#333',
            fontSize: 18
          }
        },

        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical', // 图例垂直布局2
          right: '-3%', // 图例靠右
          top: 'center', // 图例居中
          textStyle: {
            color: '#fff' // 图例文字颜色
          },
        },
        series: [
          {
            name: '学生分布',
            type: 'pie',
            radius: '50%',
            center: ['38%', '50%'],
            data: [
              {value: 2334, name: '机电工程学院'},
              {value: 2730, name: '交通工程学院'},
              {value: 2499, name: '土木建筑工程学院'},
              {value: 2640, name: '信息工程学院'}
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            label: {
              color: '#fff',
              formatter: '{c}', // 显示数值
            }
          }
        ],
      };

      // 设置配置项
      chart.setOption(option);
    },
    initOnlinePeople() {
      // 初始化图表
      const chart = echarts.init(this.$refs.onlinePeople);

      // 配置项
      const option = {
        title: {
          text: '',
          left: 'center',
          top: '10%',
          textStyle: {
            color: '#333',
            fontSize: 18
          }
        },

        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical', // 图例垂直布局
          right: '-3%', // 图例靠右3
          top: 'center', // 图例居中
          textStyle: {
            color: '#fff' // 图例文字颜色
          },
        },
        series: [
          {
            name: '学生分布',
            type: 'pie',
            radius: '50%',
            center: ['38%', '50%'],
            data: [
              {value: 2334, name: '机电工程学院'},
              {value: 2730, name: '交通工程学院'},
              {value: 2499, name: '土木建筑工程学院'},
              {value: 2640, name: '信息工程学院'}
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            label: {
              color: '#fff',
              formatter: '{c}', // 显示数值
            }
          }
        ],
      };

      // 设置配置项
      chart.setOption(option);
    },
    initChart() {
      const chart = echarts.init(this.$refs.barChart);

      // 配置项
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
        },
        legend: {
          bottom: '0',
          data: ['2022级', '2023级', '2024级'],
          textStyle: {
            color: '#ffffff',
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '10%',
          containLabel: true,
        },
        xAxis: {
          type: 'value',
          axisLine: {
            lineStyle: {
              color: '#ffffff',
            },
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
              width: 1, // 网格线宽度
              type: "dashed", // 可选: 'solid' 或 'dashed'
            },
          }
        },
        yAxis: {
          type: 'category',
          data: ['信息工程', '机电工程', '交通工程', '土木建筑'],
          axisLine: {
            lineStyle: {
              color: '#ffffff',
            },
          },
          axisTick: {
            alignWithLabel: true,
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
              width: 1, // 网格线宽度
              type: "dashed", // 可选: 'solid' 或 'dashed'
            },
          }
        },
        series: [
          {
            name: '2022级',
            type: 'bar',
            data: [1142, 1129, 1260, 1254],
            itemStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [
                  { offset: 0, color: 'rgb(255,214,125)' }, // 渐变起始颜色
                  { offset: 1, color: 'rgb(255,160,77)' }, // 渐变结束颜色
                ],
              },
            },

          },
          {
            name: '2023级',
            type: 'bar',
            data: [1180, 1089, 1280, 1154],
            itemStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [
                  { offset: 0, color: 'rgb(0,211,255)' }, // 渐变起始颜色
                  { offset: 1, color: 'rgb(0,125,255)' }, // 渐变结束颜色
                ],
              },
            },
          },
          {
            name: '2024级',
            type: 'bar',
            data: [1460, 1245, 1450, 1345],
            itemStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [
                  { offset: 0, color: 'rgb(255,151,198)' }, // 渐变起始颜色
                  { offset: 1, color: 'rgb(255,81,112)' }, // 渐变结束颜色
                ],
              },
            },
          },
        ],
      };

      // 设置配置项
      chart.setOption(option);
    },
  }
}
</script>

<template>
  <div class="main-box-department">
    <div class="top-title">
      <img src = "./images/bt.svg" alt = "title">
    </div>
    <div class="time-show">
      <real-time-clock />
    </div>
    <div class="quit-button" @click="notFull()">
      <img src = "./images/quit.svg" alt = "quit">
    </div>
    <div class="layout-head">
        <report-child title="学生分布情况">
          <div>
            <div class="switch_button">
              <div class="active">里建校区</div>
              <div>里建校区</div>
            </div>
            <div ref="barChart" style="
            width: 108%;
            height: 450px;
            position: relative;
            left:-20px;z-index: 999"></div>
          </div>
        </report-child>
        <report-child title="专业人数分布">
          <div>
            <div class="switch_button" style="position: relative;top:20px;left:22px;">
              <div class="active switch_button_big">水利工程学院</div>
              <div class="switch_button_big">电力工程学院</div>
              <div class="switch_button_big">机电工程学院</div>
              <div class="switch_button_big">信息工程学院</div>
              <div class="switch_button_big">经济管理学院</div>
              <div class="switch_button_big">交通工程学院</div>
              <div class="switch_button_big">土木建筑工程学院</div>
              <div class="switch_button_big">自动化工程学院</div>
            </div>
            <div class="distribution-list">
              <div class="distribution-item">
                <div>专业名称</div>
                <div>专业代码</div>
                <div>所属学院</div>
                <div>专业人数</div>
              </div>
              <div class="distribution-item" v-for="item in 13">
                <div>水利水电建筑工程</div>
                <div>0101</div>
                <div>水利工程学院</div>
                <div>260</div>
              </div>
            </div>
        </div>
        </report-child>
    </div>
    <div class="layout-between">
      <report-child title="在校总人数">
        <div>
          <div class="switch_button">
            <div class="active">里建校区</div>
            <div>里建校区</div>
          </div>
          <div>
            <div ref="onlinePeople" style="width: 101%; height: 400px;"></div>
          </div>
        </div>
      </report-child>
      <report-child title="全校年级总人数">
        <div>
          <div ref="totalPeople" style="width: 106%; height: 400px;position: relative;left:3%;"></div>
        </div>
      </report-child>
      <report-child title="休学人数">
        <div>
          <div ref="chartContainer" style="width: 100%;height:400px;position: relative;top:-20px"></div>
        </div>
      </report-child>
      <report-child title="处分人数">
        <div>
          <div ref="disciplinaryActionPeople" style="width: 101%; height: 400px;"></div>
        </div>
      </report-child>
    </div>
    <div class="bottom-head">
      <report-child title="学生分布情况">
        <div>
          <div ref="peopleDistribution" style="width: 101%; height: 515px;"></div>
        </div>
      </report-child>
      <report-child title="专业人数分布">
        <div>
          <div ref="distributionOfProfessionalPersonnel" style="width: 100%;height:515px;position: relative;top:-20px"></div>
        </div></report-child>
    </div>
    </div>
</template>

<style scoped lang = "scss">

.top-title{
  img{
    position: relative;
    width: 100%;
  }
}
.main-box-department{
  width: 100%;
  height: 1590px;
  background-image:url("./images/background.png");
  background-color:  rgb(0,1,52);
  background-repeat: no-repeat;
  background-size: 100% auto;

  color: white;
}
// grid 三栏布局
.layout-head{
  padding: 20px 10px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 35% 65%;
  > div{
    height: 515px;
  }

}
.layout-between{
  padding: 0px 10px;
  display: grid;
  box-sizing: border-box;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  column-gap: 2px;
  //position: relative;
  //left:-20px;
  >div{
    height: 380px;
  }
}
.bottom-head{
  padding: 20px 10px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 35% 65%;
  > div{
    height: 515px;
  }

}


.switch_button{
  display: flex;
  position: absolute;
  top: 48px;
  column-gap: 10px;
  width: 100%;
  //width:420px;
  .active{
    background: linear-gradient(270deg, #00D4FF 0%, #007BFF 100%) !important;

    box-sizing: border-box;
    border: 1px solid #5191E1;
  }
  >div{
    background: linear-gradient(180deg, rgba(1, 104, 180, 0.15) 1%, rgba(81, 145, 225, 0.15) 99%);
    width: 100px;
    height: 28px;
    line-height:27px;
    box-sizing: border-box;
    border: 1px solid #5191E1;
    font-size: 14px;
    text-align: center;

    position: relative;
    cursor: pointer;

  }
  .switch_button_big{
    width: 130px;
  }
}

.distribution-list{
  display: grid;
  row-gap: 5px;
  width: 100%;
  position: relative;
  top:40px;
  > .distribution-item:nth-child(1){
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 10px;
  }
  .distribution-item{
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    text-align: center;
  }
}

.time-show{
  position: absolute;
  top:23px;
  left:20px;
}
.quit-button{
  position: absolute;
  right:16px;
  top:17px;
  cursor: pointer;
  transition: all 0.3s;
}
.quit-button:hover{
  opacity: 0.6;
}
</style>
